import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import {tag} from "./tag.js"
const model = new THREE.Group();
const loader = new GLTFLoader();
loader.load('/有光源.glb',(gltf)=>{
    model.add(gltf.scene);
    // 获取所有的粮仓节点
    const group = gltf.scene.getObjectByName("粮仓")
    group.traverse((object)=>{
        if(object.type === "Mesh"){
            console.log('object',object);
            const label = tag(object.name)
            const pos = new THREE.Vector3()
            object.getWorldPosition(pos)
            label.position.copy(pos)
            if(object.parent.name === "立筒仓"){
                label.position.y+= 36
            }else if(object.parent.name === "浅圆仓"){
                label.position.y+= 20
            }else if(object.parent.name === "平房仓"){
                label.position.y+=  17
            }
            label.scale.set(0.2,0.2,0.2)
            // label.rotateY(Math.PI/2)
            label.rotation.y = Math.PI/2
            model.add(label)
        }
    })

})
export {model};